package com.hnxxxy.sysmgr.mapper;

import com.hnxxxy.sysmgr.pojo.Log;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author：张浩东
 * @Phone：15096207164
 * @QQ：1367048164
 * @E-mail：1367048164@qq.com
 * @date:2020年6月27日11:41:18
 */

@Mapper
//@CacheNamespace(implementation = RedisMyabtisCstCache.class)
public interface ISysLogMapper {

    @Insert(value = "INSERT INTO sys_log(user_id,time,url,`describe`,describe_type,type_name,ip,parameter,methods,abnormal) " +
            "VALUES (#{userId}, #{time},#{url}, #{describe},#{describeType}, #{typeName},#{ip}, #{parameter}, #{methods}, #{abnormal})")
    @Options(useGeneratedKeys=true, keyProperty="id",keyColumn = "id")
    int insertSysLog(Log log);

    @Delete("delete from sys_log where id = #{id}")
    int deleteSysLog(Integer id);

    @Select({"<script>",
            "select * from sys_log ",
            "<where> ",
            "<if test='userId!=null and userId!=0'>",
            "and user_id like concat('%',#{userId},'%')",
            "</if>",
            "<if test='describe!=null'>",
            "and `describe` like concat('%',#{describe},'%')",
            "</if>",
            "<if test='startTime!=null || endTime!=null'>" +
            "<if test='startTime!=null'>",
            "and time &gt;= #{startTime}",
            "</if>",
            "<if test='endTime!=null'>",
            "and time &lt;= #{endTime}",
            "</if>",
            "ORDER BY time",
            "</if>",
            "</where>",
            "</script>"})
    List<Log> findAlSysLog(Log log);

}
